'use strict';
let uniID = require('uni-id')
module.exports = {
	/**
	 * XXXnameXXX
	 * @url user/pub/loginBytt 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event, context) => {
		let {
			data = {}, util, originalParam
		} = event;
		let {
			uniID,
			config,
			pubFun,
			vk,
			_
		} = util;
		let {
			appid,
			secret,
			loginRes
		} = data;
		let res = {
			code: 0,
			msg: ""
		};
		
		vk.request({
			url: 'https://developer.toutiao.com/api/apps/v2/jscode2session',
			method: 'POST',
			data: {
				appid: data.appid,
				secret: data.secret,
				code: data.loginRes.code,
				anonymous_code: data.loginRes.anonymousCode
			},
			success: (result) => {
				console.log(result)
				console.log(result.data.data.openid)
				res.data = result.data.data.openid
				return res;
			},
			fail:(result) => {
				console.log(result)
				return res;
				}
			})

	}
}
